public class test7 {


        public static int count = 0;
        public static void main(String[] args) {
            hanbai(6, 'x', 'y', 'z');
            System.out.println("共移动了：" + count + "次");

        }

        public static void hanbai(int sum, char x, char y, char z) {
            count++;
            if (sum == 1) {
                move(x, z);
            } else {
                hanbai(sum - 1, x, z, y);
                move(x, z);
                hanbai(sum - 1, y, x, z);
            }
        }

        //打印移动过程
        public static void move(char a, char b) {

            System.out.println("从" + a + "到" + b);
        }
    }


